package com.okyai.kt.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.okyai.common.annotation.Log;
import com.okyai.common.enums.BusinessType;
import com.okyai.kt.domain.TopicPlan;
import com.okyai.kt.service.ITopicPlanService;
import com.okyai.common.core.controller.BaseController;
import com.okyai.common.core.domain.AjaxResult;
import com.okyai.common.utils.poi.ExcelUtil;
import com.okyai.common.core.page.TableDataInfo;

/**
 * 项目方案组Controller
 * 
 * @author okyai
 * @date 2021-03-20
 */
@Controller
@RequestMapping("/kt/plan")
public class TopicPlanController extends BaseController
{
    private String prefix = "kt/plan";

    @Autowired
    private ITopicPlanService topicPlanService;

    @RequiresPermissions("kt:plan:view")
    @GetMapping()
    public String plan()
    {
        return prefix + "/plan";
    }

    /**
     * 查询项目方案组列表
     */
    @RequiresPermissions("kt:plan:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TopicPlan topicPlan)
    {
        startPage();
        List<TopicPlan> list = topicPlanService.selectTopicPlanList(topicPlan);
        return getDataTable(list);
    }

    /**
     * 导出项目方案组列表
     */
    @RequiresPermissions("kt:plan:export")
    @Log(title = "项目方案组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TopicPlan topicPlan)
    {
        List<TopicPlan> list = topicPlanService.selectTopicPlanList(topicPlan);
        ExcelUtil<TopicPlan> util = new ExcelUtil<TopicPlan>(TopicPlan.class);
        return util.exportExcel(list, "plan");
    }

    /**
     * 新增项目方案组
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存项目方案组
     */
    @RequiresPermissions("kt:plan:add")
    @Log(title = "项目方案组", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TopicPlan topicPlan)
    {
        return toAjax(topicPlanService.insertTopicPlan(topicPlan));
    }

    /**
     * 修改项目方案组
     */
    @GetMapping("/edit/{planId}")
    public String edit(@PathVariable("planId") Long planId, ModelMap mmap)
    {
        TopicPlan topicPlan = topicPlanService.selectTopicPlanById(planId);
        mmap.put("topicPlan", topicPlan);
        return prefix + "/edit";
    }

    /**
     * 修改保存项目方案组
     */
    @RequiresPermissions("kt:plan:edit")
    @Log(title = "项目方案组", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TopicPlan topicPlan)
    {
        return toAjax(topicPlanService.updateTopicPlan(topicPlan));
    }

    /**
     * 删除项目方案组
     */
    @RequiresPermissions("kt:plan:remove")
    @Log(title = "项目方案组", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(topicPlanService.deleteTopicPlanByIds(ids));
    }
}
